package com.walk.zworld.ui.fragment.video.model

import com.base.lib.base.event.SingleLiveEvent
import com.base.lib.base.mvvm.viewmodel.BaseRefreshViewModel

class YouVideoViewModel : BaseRefreshViewModel<DtDetailModel>() {

    var videoId: String = ""

    private val repository = YouRepository()

    fun getVideoDetail(): SingleLiveEvent<DtDetailModel>{
        var params = mutableMapOf<String, Any>()
        params["id"] = videoId
        var datas = SingleLiveEvent<DtDetailModel>()
        launchUI {
            val result = repository.getVideoDetail(params).result
            datas.value = result
        }
        return datas
    }

    fun getRandomVideoList(): SingleLiveEvent<List<DtDetailModel>>{
        var params = mutableMapOf<String, Any>()
        params["id"] = videoId
        var datas = SingleLiveEvent<List<DtDetailModel>>()
        launchUI {
            val result = repository.getRandomVideoList(params).result
            datas.value = result
        }
        return datas
    }

    override fun refreshData(params: Any?) {
        page = 0;
        launchUI {
            if (params is MutableMap<*, *>){
                (params as MutableMap<String, Any>).let {
                    it.put("page", page)
                    it.put("pageIndex", page)
                    it.put("pageSize", pageSize)
                    it.put("rows", pageSize)
                }
                mData.value = repository.getVideoList(params).result.records
            }
        }
        mData
    }
    /*    private int page=1;
    private int sort =0;//排序 0（综合） 1（最热） 2（最新）
    private int type =2;//类型 0（图文） 1（视频）2（图文和视频）*/

    override fun loadMore(params: Any?) {
        page += 1;
        launchUI {
            if (params is MutableMap<*, *>){
                (params as MutableMap<String, Any>).let {
                    it.put("page", page)
                    it.put("pageIndex", page)
                    it.put("pageSize", pageSize)
                    it.put("rows", pageSize)
                }
                mData.value = repository.getVideoList(params).result.records
            }
        }
        mData
    }
}